package genesis

import (
	"encoding/json"
)

var (
	poaGene = PoaGenesis{
		Config: Config{
			ChainID:        3781,
			HomesteadBlock: 1,
			Eip150Block:    2,
			Eip150Hash:     "0x0000000000000000000000000000000000000000000000000000000000000000",
			Eip155Block:    3,
			Eip158Block:    3,
			Clique: PoaClique{
				Period: 3,
				Epoch:  30000,
			},
		},
		Nonce:      "0x0",
		Timestamp:  "0x59ba3140",
		ExtraData:  "0x000000000000000000000000000000000000000000000000000000000000000016d071a5374281dd27f2c946c08bd01283ec86eb8220f95f8db7bacf4313c2906f2800e537715192bc43dec69f2198fc6b08502e2d7da2efba38c8ed000000000000000000000000000    0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
		GasLimit:   "0x47b760",
		Difficulty: "0x1",
		MixHash:    "0x0000000000000000000000000000000000000000000000000000000000000000",
		Coinbase:   "0x0000000000000000000000000000000000000000",
		Alloc:      make(map[string]Balance, 0),
		Number:     0,
		GasUsed:    "0x0",
		ParentHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
	}
)

func AddBalance(addrs []string) {
	for _, addr := range addrs {
		poaGene.Alloc[addr] = Balance{
			B: "0x200000000000000000000000000000000000000000000000000000000000000",
		}
	}
}

func MakeGenesisJson() []byte {
	geneBytes, _ := json.Marshal(poaGene)

	return geneBytes
}

type PoaGenesis struct {
	Config     Config `json:"config"`
	Nonce      string `json:"nonce"`
	Timestamp  string `json:"timestamp"`
	ExtraData  string `json:"extraData"`
	GasLimit   string `json:"gasLimit"`
	Difficulty string `json:"difficulty"`
	MixHash    string `json:"mixHash"`
	Coinbase   string `json:"coinbase"`
	Alloc      Alloc  `json:"alloc"`
	Number     int    `json:"number"`
	GasUsed    string `json:"gasUsed"`
	ParentHash string `json:"parentHash"`
}
type PoaClique struct {
	Period int `json:"period"`
	Epoch  int `json:"epoch"`
}
type Config struct {
	ChainID        int       `json:"chainId"`
	HomesteadBlock int       `json:"homesteadBlock"`
	Eip150Block    int       `json:"eip150Block"`
	Eip150Hash     string    `json:"eip150Hash"`
	Eip155Block    int       `json:"eip155Block"`
	Eip158Block    int       `json:"eip158Block"`
	Clique         PoaClique `json:"clique"`
}
type One6D071A5374281Dd27F2C946C08Bd01283Ec86Eb struct {
	Balance string `json:"balance"`
}
type Eight220F95F8Db7Bacf4313C2906F2800E537715192 struct {
	Balance string `json:"balance"`
}
type Bc43Dec69F2198Fc6B08502E2D7Da2Efba38C8Ed struct {
	Balance string `json:"balance"`
}
type Alloc map[string]Balance

type Balance struct {
	B string `json:"balance"`
}
